'use strict';


const db = uniCloud.database();
const dbCmd = db.command // 取指令

async function comment(event){
	console.log(event)
	const { order_id, hotel_id, start  } = event
	await db.collection('order').doc(order_id).update({
		isComments : true
	})
	await db.collection('xinxuan_hotel').doc(hotel_id).update({
		score : dbCmd.inc(start),
		comment_count: dbCmd.inc(1)
	})
	await db.collection('xinxuan_hotel').doc(hotel_id).update({
		score : dbCmd.mul(0.5)
	})
	let orderUpdateResult = await db.collection('xinxuan_comments').add(event);
	
	
	if (orderUpdateResult.id || orderUpdateResult.updated === 1) {
		return {
			code: 0,
			msg: '评论成功'
		}
	} else{
		return {
			code: -1,
			msg: '评论失败'
		}
	}
}

exports.main = comment;